package com.sailfish.springbootdemo.controller.db1;

import com.sailfish.springbootdemo.pojo.Result;
import com.sailfish.springbootdemo.pojo.db1.PcbaDeviceRelatedTechParam;
import com.sailfish.springbootdemo.service.db1.PcbaDeviceRelatedDeviceParamService;
import com.sailfish.springbootdemo.service.db1.PcbaDeviceRelatedTechParamService;
import com.sailfish.springbootdemo.utils.ResultUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@CrossOrigin
@RequestMapping("/pcbaDeviceRelatedTechDeviceParam")
public class PcbaDeviceRelatedTechDeviceParamController {

    @Autowired
    private PcbaDeviceRelatedTechParamService pcbaDeviceRelatedTechParamService;

    @PostMapping("/getAllByDeviceResourceId")
    public Result getAllByDeviceResourceId(Integer pcbaDeviceResourceId) {
        try {
            if (pcbaDeviceResourceId == null || "".equals(pcbaDeviceResourceId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaDeviceResourceId", "Miss Param pcbaDeviceResourceId", null);
            }
            return ResultUtil.success(pcbaDeviceRelatedTechParamService.getAllByDeviceResourceId(pcbaDeviceResourceId));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }

    @PostMapping("/getPcbaDeviceRelatedTechParamByResourceIdAndKey")
    public Result getPcbaDeviceRelatedTechParamByResourceIdAndKey(Integer pcbaDeviceResourceId, String techDeviceParamKey) {
        try {
            if (pcbaDeviceResourceId == null || "".equals(pcbaDeviceResourceId.toString())) {
                return ResultUtil.error(500, "缺少参数pcbaDeviceResourceId", "Miss Param pcbaDeviceResourceId", null);
            }
            if (techDeviceParamKey == null || "".equals(techDeviceParamKey)) {
                return ResultUtil.error(500, "缺少参数techDeviceParamKey", "Miss Param techDeviceParamKey", null);
            }
            return ResultUtil.success(pcbaDeviceRelatedTechParamService.getPcbaDeviceRelatedTechParamByResourceIdAndKey(pcbaDeviceResourceId, techDeviceParamKey));
        } catch (Exception e) {
            e.printStackTrace();
            return ResultUtil.error(500, e.getMessage(), e.getMessage(), null);
        }
    }
}
